<?php
class Public_room extends CI_Controller 
{
	function __construct()
	{
		parent::__construct();
		if((!check_auth()) ? redirect("/login/auth") : site_url("/home"));
		$this->load->model('public_model');
	}
	
	/*********************************************************
	**	MODULE MEETING ROOM									**
	**	AUTHOR 			: ERY								**
	**	DATE CREATED	: 19/05/2014						**
	*********************************************************/
	function meeting_room()
	{
		$data['dtNow'] 			= date("d/m/Y",now());
		$data['room_select'] 	= $this->public_model->getMeetingRoomList();
		
		$data['list_data_item'] = $this->public_model->list_data_item();      //tambahan by Surya Alam Gultom - Jumat, 4 Juli 2014 10:59 AM
		$data['count_data'] 	= $this->public_model->count_data();
		
		//$this->getView($this->uri->segment(1),$this->uri->segment(2),$data);	//revisi by Surya Alam Gultom - Jumat, 1 Agustus 2014 10:59 PM
		$this->getView(public_room,meeting_room,$data);
	}
	
	//===============================================================================================================
    // INSERT MEETING ROOM CONTROLLER - OTHER LOCATION ~ SURYA ALAM GULTOM 
    //===============================================================================================================
	
	function insert_reservasi() {
        //$arr['r_id'] = trim($this->input->post('r_id'));
		
		$data['pesan'] = "Maaf Order anda pada tgl 00/00/000 00:00 ~ 00:00 Tidak Berhasil!";
		
		//$data['pesan'] = $this->public_model->insert_dmr($arr);
        // $this->session->set_flashdata('Success', 'Data successfully inserted!');
    	
		//$data['pesan'] = $this->public_model->getMsg();
		$this->load->view('room_notification', $data);
    }

	
	function add_room()  //tambahan by Surya Alam Gultom - Sabtu, 2 Agustus 2014 12:54 AM 
	{
		$data['dtNow'] 			= date("d/m/Y",now());
		$data['room_select'] 	= $this->public_model->getMeetingRoomList();
		$data['request_select'] = $this->public_model->getRequest();
		$data['list_data_item'] = $this->public_model->list_data_item();      
		$data['count_data'] 	= $this->public_model->count_data();
		
		$room_split = explode("_",$_POST['room_select']);	//update Rabu, 13 Agustus 2014 3:19 PM
		$room_name = $room_split[2];
		$floor_id = $room_split[1];
		$cat_id = $room_split[0];
		
		//var_dump($room_split); exit;
		
		$data['category'] 	= $room_name;
		$data['type'] 		= $this->public_model->getRoomType($cat_id);
		$data['floor'] 		= $this->public_model->getRoomFloor($floor_id);		
		
		$this->load->view('public_room/meeting_room_2', $data);
	}
	
	function showAll() //tambahan by Surya Alam Gultom - Jumat, 25 Juli 2014 11:29 AM
	{
		$room_split = explode("_",$_POST['room_select']);
		//$room_name = $room_split[2];
		$floor_id = $room_split[1];
		$cat_id = $room_split[0];
		
		$data['capacity'] 	= $this->public_model->getRoomCapacity($cat_id);
		$data['floor'] 		= $this->public_model->getRoomFloor($floor_id);		
		
		$this->load->view($this->uri->segment(1).'/'.$this->uri->segment(2),$data);
	}
	
	function showRequest() //tambahan by Surya Alam Gultom - Selasa, 12 Agustus 2014 04:06 PM
	{
		$arr['Nik']   			= trim($this->input->post('request_select'));
		$data['Detail']			= $this->public_model->getDetailReq($arr);		
		
		//var_dump($data['Detail']); exit;		
		
		//echo $data['Detail']['HR_ID']; exit;
		
		$data['request_select'] = $this->public_model->getRequest();
		
		$data['list_data_item'] = $this->public_model->list_data_item();      
		$data['count_data'] 	= $this->public_model->count_data();
		
		$this->load->view($this->uri->segment(1).'/'.$this->uri->segment(2),$data);		
	}
	
	function showRoom()
	{
		$oddeven = '';
		if ($_POST['room_select'] != "Select Room")
		{
			$room_split = explode("_",$_POST['room_select']);
			$room_name = $room_split[2];
			$floor_id = $room_split[1];
			$cat_id = $room_split[0];
			
			$dateSelect = $this->input->post('date_select');
			$showTime = $this->public_model->getFullTime();
		
			foreach($showTime as $showTime)
			{
				$y=0; $x=0;
				$aTimeId = $showTime["TIME_ID"];
				$aTimeName = $showTime["TIME_NAME"];
				
				//$aTimeStatus = $showTime['TIME_STATUS'];  //revisi by Surya Alam Gultom - Sabtu, 2 Agustus 2014 12:41 AM
				$aTimeStatus = 'N';
				
				$RoomCheck = $this->public_model->getRoomAvailable($room_name,$floor_id,$dateSelect);
				
				if($RoomCheck != FALSE)
				{
					foreach($RoomCheck as $RoomCheck)
					{
						$TimeId = $RoomCheck['TIME_ID'];
						if ($TimeId == $aTimeId) 
						{
							if ($y == 0)
							{
								$y = 1;
								$aTimeStatus = "N";
								$x = $x + 1;
							}
							else
							{
								$y = 0;
								$aTimeStatus = "N";
								$x = $x + 1;
							}
						}
						else 
						{
							if ($y == 1)
							{
								$aTimeStatus = "N";
								$y == 1;
								$x = $x + 1;
							}
							else
							{
								$aTimeStatus = "Y";
								$y = 0;
							}
						}
						if ($x > 0)
						{
							$x = 0;
							$aTimeStatus = "N";
						}
						
					}
					
					$Room_Booking = $this->public_model->getRoomName($room_name,$floor_id,$dateSelect,$aTimeId);
					//$judul = $Room_Booking['ROOM_DESCRIPTION'];
					$roomId = $Room_Booking['ROOM_ID'];
					$usrname = $Room_Booking['NAME'];
					
					$Floor_name = $this->public_model->getFloor();
					$vFloor = $Floor_name['MST_FLOOR_DESC'];
				}
				
				//$ForShowjudul[] = $judul;
				$ForShowTime[] = $aTimeName;
				$datstat[] = $aTimeStatus;
				
				/*
				if (!empty($floor_id) && !empty($dateSelect)) 						//revisi by Surya Alam Gultom - Sabtu, 2 Agustus 2014 12:46 AM
				{
					$request = $this->public_model->getRequestor($floor_id);
					$cnt = $request['CNT'];
					if ($cnt == 1) 
					{
						echo '<img src="'.base_url().'static/images/edit.gif"/>';
					} 
					else 
					{
						$imgedit = "";
					}
					$aTimeStatus = "Y";
					$judul = "";
					$imgorder = "";
					$imgedit = "";
					$bgcolor = "";
					$usrname = "";
					$roomId = "";
				}
				*/
								
			}
			
			//$data['Showjudul'] = $ForShowjudul;
			$data['ShowRoomProp'] = $this->public_model->getRoomProp($cat_id);
			$data['ShowTime'] 	  = $ForShowTime;
			$data['ShowStatus']   = $datstat;
			
			//var_dump($data); return false;
		}		
		$this->load->view($this->uri->segment(1).'/'.$this->uri->segment(2),$data);
	}
	
	/*********************************************************
	**	MODULE MAILING ROOM									**
	**	AUTHOR 			: ERY								**
	**	DATE CREATED	: 19/05/2014						**
	*********************************************************/	
	function mailing_room()
	{
		$data['dtNow'] = date("d/m/Y",now());
		$data['P_Time'] = $this->public_model->getTimePick(); 
		$this->getView($this->uri->segment(1),$this->uri->segment(2),$data);
	}
	
	//===============================================================================================================
    // INSERT MAILING ROOM CONTROLLER ~ SURYA ALAM GULTOM 
    //===============================================================================================================
	
	function insert_dmr() {
        $arr['r_id'] = trim($this->input->post('r_id'));
		$arr['r_mgr'] = trim($this->input->post('r_mgr'));
		$arr['courier'] = trim($this->input->post('courier'));
        $arr['category'] = trim($this->input->post('category')); 
        $arr['cargo_type'] = trim($this->input->post('cargo_type'));
        $arr['location'] = trim($this->input->post('location'));
        $arr['timed'] = trim($this->input->post('timed'));
        $arr['D_Area'] = trim($this->input->post('D_Area'));
        $arr['D_Regional'] = trim($this->input->post('D_Regional'));
        $arr['lantai'] = trim($this->input->post('lantai'));		
        $arr['weight'] = trim($this->input->post('weight'));
		$arr['deskripsi'] = trim($this->input->post('deskripsi'));
		
		//$data['pesan'] = "FM : Order No 007 telah berhasil, untuk Proses selanjutnya menunggu Approval dari atasan anda SURYA";
		
		$data['pesan'] = $this->public_model->insert_dmr($arr);
        $this->load->view('room_notification', $data);
    }

	/*=======================================================
	 Function 		: Show Area Name
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/
    function ShowArea()
	{
		$Courier = $_POST['courier_id'];
		if (strlen($Courier) < 2)
		{
			$data['get_Area'] = 0;
		}
		else
		{
			if($Courier == 'DOM')
			{
				$cond = "AND ISDOMESTIC ='Y'";
				$data['get_Area'] = $this->public_model->getArea($cond);
			}
			elseif($Courier == 'INT')
			{
				$cond = "AND ISDOMESTIC ='N'";
				$data['get_Area'] = $this->public_model->getArea($cond);
			}
			else
			{
				$cond = "AND ISMESSENGER ='Y'";
				$data['get_Area'] = $this->public_model->getArea($cond);
			}
		}
        $this->load->view($this->uri->segment(2),$data);
    }

	/*=======================================================
	 Function 		: Filter Regional Name select By AREA
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/
	function getfilterRegional()
	{
		$D_Region = $_POST['getRegion'];
		$Search_Region = $this->public_model->getfilRegional($D_Region);
		if ($Search_Region != FALSE)
		{
			foreach($Search_Region AS $Search_Region)
			{
				$arr_Name[] = $Search_Region;
			}
		}
		else
		{
			$arr_Name[] = array('REGIONAL_NAME' => 'No matches found');
		}
		$data['Show_Region'] = $arr_Name;	
		echo json_encode($data);
	}

	/*=======================================================
	 Function 		: Show Regional Name
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/
	function getRegional()
	{
		$Search_Region = $_POST['SearchReg']['get_Regional'];
		if ($Search_Region != FALSE)
		{
			foreach($Search_Region AS $Search_Region)
			{
				$arr_Name[] = $Search_Region;
			}
		}
		else
		{
			$arr_Name[] = array('REGIONAL_NAME' => 'No matches found');
		}
		$data['Show_Region'] = $arr_Name;	
		echo json_encode($data);
	}
	
	/*=======================================================
	 Function 		: Show Regional Name
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/
    function ShowRegional()
	{
		$area_name = str_replace("-"," ",$_POST['area_name']);
		$arr_name = $this->public_model->getRegional($area_name);
		$data['get_Regional'] = $arr_name;
		echo json_encode($data);
    }
	
	/*********************************************************
	**	MODULE GLOBALS	Search NIK							**
	**	AUTHOR 			: ERY								**
	**	CREATED	DATE	: 19/05/2014						**
	*********************************************************/
	/*=======================================================
	 Function 		: Search ID, Employee Name, Manager, 
	 				  department and job position
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/
	/*=======================================================
	 MODIFIED DATE	: 22/05/2014
	 MODIFIED BY	: ERY
	 =======================================================*/	
	function globals_nik_Search()
	{
		$Emp_Name[] = SearchDetailEmp($this->security->xss_clean($this->input->post('SearchName')));
		foreach($Emp_Name AS $Emp_Name =>$keyVal)
		{
			$data['Show_Name'] = $keyVal['arr_Name'];
		}
		echo json_encode($data);
	}
	
	function globals_nik_detail()
	{
		$data['DetailEmp'] = putDetailEmp($this->security->xss_clean($this->input->post('id')));
		echo json_encode($data);
	}

	/*=======================================================
	 Function 		: Load static header and footer view page 
	 				  and dinamic page view page from each 
					  function 
	 AUTHOR			: ERY
	 CREATED DATE	: 19/05/2014
	=======================================================*/	
	function getView($P_Menu,$S_Menu, $data)
	{
		$this->load->view('header');
		if ($data)
		{
		//	var_dump($data);
			$this->load->view($P_Menu.'/'.$S_Menu,$data);
		}
		else
		{
		//	var_dump($data);
			$this->load->view($P_Menu.'/'.$S_Menu);
		}
		$this->load->view('footer');
	}
}
?>